package com.xpp.crowd.handler;

import com.xpp.crowd.entity.vo.DetailProjectVO;
import com.xpp.crowd.entity.vo.ProjectVO;
import com.xpp.crowd.entity.vo.ProtalProjectVO;
import com.xpp.crowd.entity.vo.ProtalTypeVO;
import com.xpp.crowd.service.api.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xpp.util.ResultEntity;

import java.util.List;

@RestController
public class ProjectProviderHandler {

    @Autowired
    private ProjectService projectService;
    // 将ProjectVO中的数据存入各个数据库
    @RequestMapping("/save/project/vo/remote")
    public ResultEntity<String> saveProjectVORemote(
            @RequestBody ProjectVO projectVO,
            @RequestParam("memberId") Integer memberId){
        // 调用本地service进行保存
        try {
            projectService.saveProject(projectVO, memberId);
            return ResultEntity.successWithoutData();
        } catch (Exception e){
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }

    @RequestMapping("/get/protal/type/project/data/remote")
    public ResultEntity<List<ProtalTypeVO>> getProtalTypeProjectDataRemote(){
            try {
                List<ProtalTypeVO> protalTypeVOList = projectService.getPortalTypeVO();
                return ResultEntity.successData(protalTypeVOList);
            }catch (Exception e){
                e.printStackTrace();
                return ResultEntity.failed(e.getMessage());
            }
    }

    @RequestMapping("/get/project/detail/remote/{projectId}")
    public ResultEntity<DetailProjectVO> getDetailProjectVORemote(@PathVariable("projectId") Integer projectId) {
        try {
            DetailProjectVO detailProjectVO = projectService.getDetailProjectVO(projectId);
            return ResultEntity.successData(detailProjectVO);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }
}
